﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZhouYu.DreamTour.Core;
using ZhouYu.DreamTour.DAL.IRepository;
using ZhouYu.DreamTour.Model;

namespace ZhouYu.DreamTour.DAL.Repository
{
  public  class PaymentRecordRepository: IPaymentRecordRepository
    {
        #region 支付成功时添加支付记录
        /// <summary>
        /// 支付成功时添加支付记录
        /// </summary>
        /// <param name="paymentRecord"></param>
        /// <returns></returns>
        public bool AddPaymentRecordInfo(PaymentRecord paymentRecord)
        {
            paymentRecord.Payment_Status = 0;//状态未通知
            string sql = @"INSERT INTO PaymentRecord(User_Id,`Payment_OrderNo`,`Payment_OrderName`,`Payment_OrderRemark`,`Payment_Amount`,Payment_OutingTime,Payment_Status)
                            VALUES(@User_Id,@Payment_OrderNo,@Payment_OrderName,@Payment_OrderRemark,@Payment_Amount,@Payment_OutingTime,@Payment_Status);";
            return DapperHelper<PaymentRecord>.Execute(sql, paymentRecord) > 0;
        }
        #endregion

        #region 查询支付记录
        /// <summary>
        /// 查询支付记录
        /// </summary>
        /// <returns></returns>
        public List<PaymentRecord> SelPaymentRecordInfo()
        {
            string sql = @"SELECT * FROM PaymentRecord where Payment_Status=0";
            return DapperHelper<PaymentRecord>.QueryList(sql, null);
        }
        #endregion

        #region 修改支付通知状态
        /// <summary>
        /// 修改支付通知状态
        /// </summary>
        /// <param name="Payment_Status"></param>
        /// <param name="Payment_OrderNo"></param>
        /// <returns></returns>
        public bool UpdatePaymentStatus(int Payment_Status, string Payment_OrderNo)
        {
            string sql = @"UPDATE paymentrecord SET Payment_Status=@Payment_Status WHERE Payment_OrderNo=@Payment_OrderNo";
            return DapperHelper<PaymentRecord>.Execute(sql,new { Payment_Status = Payment_Status, Payment_OrderNo = Payment_OrderNo })>0;
        }
        #endregion
    }
}
